<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>验收请求</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    <c:import url="admin_home.jsp"></c:import>
    
    
    
    
    <div class="container">
    	
    	<div class="row ">
    	
    		<!-- 通过 Modal -->
    		<div class="modal fade bs-example-modal-lg" id="passModal" tabindex="-1" role="dialog" aria-labelledby="passModalLabel">
			  <div class="modal-dialog" style="margin-right: 1000px" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="myModalLabel">验收信息</h4>
			      </div>
			      <div class="modal-body">
			        <form class="form-horizontal" id="pass_form">
			        	<div class="form-group">
			        		<label  class="col-sm-3 control-label">项目名称</label>
						    <div class="col-sm-5">
						      <input type="text" class="layui-input" id="projectName" name="projectName" disabled>
						      <input type="hidden" id="projectId" name="projectId">
						    </div>
				      </div>
					  <div class="form-group">
					    <label  class="col-sm-3 control-label">验收时间</label>
					    <div class="col-sm-5">
					      
					      <input type="text" class="layui-input" id="checkTime" name="checkTime" placeholder="选择验收时间">
					    </div>
					  </div>
					  <div class="form-group">
					    <label  class="col-sm-3 control-label">验收地点</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="checkAddress" name="checkAddress" placeholder="输入验收地点">
					    <span id="helpBlock2" class="help-block"></span>
					    </div>
					  </div>
					  
					  <div class="form-group">
					    <label  class="col-sm-3 control-label" placeholder="输入验收要求...">验收要求</label>
					    <div class="col-sm-8">
					      <textarea id="check_claim" name="check_claim" class="form-control" rows="3" placeholder="验收要求..."></textarea>
					    	
					    </div>
					  </div>
					</form>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			        <button type="button" class="btn btn-primary" id="btn_successCheck">确定</button>
			      </div>
			    </div>
			  </div>
			</div>
			
			<!-- 驳回 Modal -->
			<div class="modal fade bs-example-modal-lg" id="failModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			  <div class="modal-dialog" style="margin-right: 1000px" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="myModalLabel">驳回信息</h4>
			      </div>
			      <div class="modal-body">
			        <form class="form-horizontal" id="fail_form">
			        	<div class="form-group">
			        		<label  class="col-sm-3 control-label">项目名称</label>
						    <div class="col-sm-5">
						      <input type="text" class="layui-input" id="fail_projectName" name="fail_projectName" disabled>
						      <input type="hidden" id="fail_projectId" name="fail_projectId">
						    </div>
				      </div>
					  <div class="form-group">
					    <label  class="col-sm-3 control-label" placeholder="输入验收要求...">驳回说明</label>
					    <div class="col-sm-8">
					      <textarea id="failCheckInfo" name="failCheckInfo" class="form-control" rows="3" placeholder="请输入驳回理由..."></textarea>
					    	
					    </div>
					  </div>
					</form>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			        <button type="button" class="btn btn-primary" id="btn_failCheck">确定</button>
			      </div>
			    </div>
			  </div>
			</div>
			
			<!-- 设置验收结果 Modal -->
			<div class="modal fade bs-example-modal-lg" id="resultModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			  <div class="modal-dialog" style="margin-right: 1000px" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="myModalLabel">设置验收结果</h4>
			      </div>
			      <div class="modal-body">
			      
			      	<form class="form-horizontal" id="result_form">
			      		<input type="hidden" id="result_projectId" name="projectId">
			        	<div class="form-group">
			        		<label  class="col-sm-3 control-label">项目名称</label>
						    <div class="col-sm-5">
						      <input type="text" class="layui-input" id="result_projectName" name="projectName" disabled>
						    </div>
				      	</div>
				      	<div class="form-group" >
				      		<label class="col-sm-3 control-label">回收房间</label>
				      		<div class="col-sm-5" style="margin-top: 7px">
				      			<input type="radio" name="rebackRoom" id="optionsRadios1" value="1" checked>回收&nbsp;&nbsp;
				      			<input type="radio" name="rebackRoom" id="optionsRadios2" value="0">暂不回收
				      		</div>
				      	</div>
				      	
				      	<div class="form-group">
						    <label class="col-sm-3 control-label">评分</label>
						    <div class="col-sm-5">
						    	<div id="result_rate"></div>
						    </div>
						    <input type="hidden" id="input_result_rate" name="pro_rate">
						</div>
						<div class="form-group">
						    <label class="col-sm-3 control-label">评语</label>
						    <div class="col-sm-8">
					      		<textarea id="resultCheckInfo" name="pro_comment" class="form-control" rows="5" placeholder="请输入评语..."></textarea>
					    	</div>
						</div>
				     </form>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			        <button type="button" class="btn btn-primary" id="result_failCheck">确定</button>
			      </div>
			    </div>
			  </div>
			</div>
			
    	</div>
		
    <!-- 显示表格数据 -->
    <div class="layui-body " style="margin-top: 100px">
    	
     		<div class="layui-row" style="margin-top: 10px">
     			<div class="layui-col-md12">
     				<table class="table table-hover" id="memberTable">
     					<thead>
     					<tr>
     						<th>ID</th>
     						<th>项目名称</th>
     						<th>项目组长</th>
     						<th>提交申请时间</th>
     						<th>验收时间</th>
     						<th>验收地点</th>
     						<th>验收要求</th>
     						<th>项目报告</th>
     						
     						<th>状态</th>
     						<th>操作</th>
     					</tr>
     					</thead>
     					<tbody>
     					<c:if test="${list==null} or ${list.size()==0} ">	
     						未有验收请求
     					</c:if>
     					<c:if test="${list.size()>0}">
     						<c:forEach items="${list}" var="pro" varStatus="status">
     							<tr>
     								<td>${status.index+1}</td>
     								<td>${pro.projectName}</td>
     								<td>${pro.leaderName}</td>
     								<td>${pro.submit_time}</td>
     								<td>
     									<c:if test="${pro.applyStatus<1}">
     										未设置
     									</c:if>
     									<c:if test="${pro.applyStatus>=1}">
     										${pro.checkTime}
     									</c:if>
     								</td>
     								<td>
     									<c:if test="${pro.applyStatus<1}">
     										未设置
     									</c:if>
     									<c:if test="${pro.applyStatus>=1}">
     										${pro.checkAddress}
     									</c:if>
     								</td>
     								<td>
     									<c:if test="${pro.applyStatus<1}">
     										未设置
     									</c:if>
     									<c:if test="${pro.applyStatus>=1}">
     										<a href="javascrip:void(0)" onclick="show_checkClaim('${pro.check_claim}')">查看</a>
     									</c:if>
     								</td>
     								<td><a href="${pageContext.request.contextPath}/file/downloadProjectFile.do?fileId=${pro.projectReport}">下载</a></td>
     								
     								<td>
     									<c:if test="${pro.applyStatus==0}">
     										待处理
     									</c:if>
     									<c:if test="${pro.applyStatus==1}">
     										已处理
     									</c:if>
     									<c:if test="${pro.applyStatus==3}">
     										已驳回
     									</c:if>
     									<c:if test="${pro.applyStatus==2}">
     										验收成功
     									</c:if>
     								</td>
     								<td>
     									<c:if test="${pro.applyStatus==0}">
     										<a href="#" onclick="setGroupId(1,'${pro.projectName}','${pro.projectId}')" data-toggle="modal" data-target="#passModal">通过</a>&nbsp;|&nbsp;
     										<a href="#" onclick="setGroupId(0,'${pro.projectName}','${pro.projectId}')" data-toggle="modal" data-target="#failModal">驳回</a>
     									</c:if>
     									<c:if test="${pro.applyStatus==1}">
     										<a href="javascrip:void(0);" onclick="setRsult('${pro.projectName}','${pro.projectId}','${pro.checkTime}')">设置验收结果</a>
     									</c:if>
     									<c:if test="${pro.applyStatus==2}">
     										无
     									</c:if>
     									<c:if test="${pro.applyStatus==3}">
     										无
     									</c:if>
     								</td>
     							</tr>
     						</c:forEach>
     					</c:if>
     					
     					</tbody>
     					</table>
     			</div>
     		</div>
     	</div>
     </div>

<script type="text/javascript">		

//日期时间范围选择
//日期选择
	  layui.use('laydate', function(){
	    var laydate = layui.laydate;
	    
	    //执行一个laydate实例
	    laydate.render({
	      elem: '#checkTime' //指定元素
	      ,min:getNowDay()
	      ,type: 'datetime'
	    });
	  });
	  
	//获取当前时间(yyyy-MM-dd)
	  function getNowDay(){
	  	var now_day=new Date();
	  	var day=now_day.getDate();
	  	var month=now_day.getMonth()+1;
	  	var year=now_day.getFullYear();
	  	var now_day_String=year+"-"+month+"-"+day;
	  	console.log("now_day_String:"+now_day_String);
	  	return now_day_String;
	  }
	//查看验收要求
	  function show_checkClaim(info){
	    	console.log(info);
	    	
	    	 layer.alert(info, {
	    		    skin: 'layui-layer-lan'
	    		    ,title:'验收要求'
	    		    ,closeBtn: 0
	    		    ,anim: 4 //动画类型
	    		  });
	    }
//评分
$("#result_rate").raty({
	number:5,
	path:'${pageContext.request.contextPath}/img/star',
	half:true,
	starOn:'star-on.png',
	starOff:'star-off.png',
	click:function(score,evt){
		$("#input_result_rate").val(score);
		console.log(score);
		console.log(evt);
	}
	
});
//模态框中设置groupId
function setGroupId(num,projectName,projectId){
	console.log(num);console.log(projectName);console.log(projectId);
	if(num==1){
		//同意验收
		$("#projectName").val(projectName);
		$("#projectId").val(projectId);
	}else if(num==0){
		//驳回验收请求
		$("#fail_projectName").val(projectName);
		$("#fail_projectId").val(projectId);
	}
	
}
function setRsult(projectName,projectId,checkTime){
	console.log(projectName);console.log(projectId);
	console.log(checkTime);
	var mydate=new Date();
	var day=getNowDay();
	var hours=mydate.getHours();
	var minutes=mydate.getMinutes();
	var seconds=mydate.getSeconds();
	var nowTime=day+" "+hours+":"+minutes+":"+seconds;

	var d1=new Date(Date.parse(checkTime));
	var d1=new Date(Date.parse(nowTime));
	if(checkTime>nowTime){
		console.log("时间未到");
		layer.msg('验收时间未到', {icon: 2});
	}else if(checkTime<nowTime){
		console.log("时间已过");
		$("#result_projectName").val(projectName);
		$("#result_projectId").val(projectId);
		$("#resultModal").modal('toggle');//打开模态框
	}
	
}

//准许验收
$("#btn_successCheck").click(function(){
	var projectId=$("#projectId").val();
	var checkTime=$("#checkTime").val();
	var checkAddress=$("#checkAddress").val();
	var check_claim=$("#check_claim").val();
	console.log("projectId"+projectId);
	console.log(checkTime);console.log(checkAddress);
	console.log(check_claim);
	if(checkTime==null||checkTime==""){
		layer.msg('验收时间不能为空', {icon: 2});
		return;
	}else if(checkAddress==null||checkAddress==""){
		layer.msg('验收地点不能为空', {icon: 2});
		return;
	}
	console.log($("#pass_form").serialize());
	$.ajax({
		url:"${pageContext.request.contextPath}/admin/success_checkPro.do",
		data:{"projectId":projectId,"checkTime":checkTime,"checkAddress":checkAddress,"check_claim":check_claim},
		type:"POST",
		success:function(result){
			$("#passModal").modal("hide");
			if(result.code==100){
				
				layer.msg('处理成功', {icon: 1,time:2000,end:function(){
					location.reload();
				}});
				//location.reload();
				//$("#submit_ok").append("<div></div>").addClass("alert alert-success").attr("role","alert").append("提交成功");
			}else if(result.code==200){
				layer.msg('处理失败'+result.extend.errorMsg, {icon: 2});
			}
			
		}
	});
});
//驳回验收请求
$("#btn_failCheck").click(function(){
	var failCheckInfo=$("#failCheckInfo").val();
	var projectId=$("#fail_projectId").val();
	console.log(projectId);console.log(failCheckInfo);
	if(failCheckInfo==null||failCheckInfo==""){
		layer.msg('驳回说明不能为空', {icon: 2});
		return;
	}
	$.ajax({
		url:"${pageContext.request.contextPath}/admin/fail_checkPro.do",
		data:{"failCheckInfo":failCheckInfo,"projectId":projectId},
		type:"GET",
		success:function(result){
			$("#failModal").modal("hide");
			if(result.code==100){
				
				layer.msg('处理成功', {icon: 1});
				
			}else if(result.code==200){
				layer.msg('处理失败'+result.extend.errorMsg, {icon: 2});
			}
		}
	});
	
});
//设置验收结果
$("#result_failCheck").click(function(){
	var rate=$("#input_result_rate").val();
	var resultCheckInfo=$("#resultCheckInfo").val();
	var projectId=$("#result_projectId").val();
	var rebackRoom=$("input[name='rebackRoom']:checked").val();
	console.log("projectId:"+projectId+",pro_rate:"+rate+",pro_comment:"+resultCheckInfo);
	if(rate==""){
		layer.msg('请为项目评分！', {icon: 2});
		return;
	}else if(resultCheckInfo==""){
		layer.msg('请写入项目得到评语！', {icon: 2});
		return;
	}
	$("#resultModal").modal('toggle');
	$.ajax({
		url:"${pageContext.request.contextPath}/admin/checkResult.do",
		data:{"projectId":projectId,"pro_rate":rate,"pro_comment":resultCheckInfo,"rebackRoom":rebackRoom},
		type:"GET",
		success:function(result){
			if(result.code=100){
				layer.msg('处理成功', {icon: 1,time:2000,end:function(){
					location.reload();
				}});
			}else{
				layer.msg('处理失败！', {icon: 2});
			}
		}
	});
});
</script>
  </body>
</html>
